package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.cache.GuiGuCache;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.websocket.OnOpen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

    @Autowired
    private BaseCategoryService baseCategoryService;


    /**
     * 查询所有分类（1、2、3级分类）在一级分类下包含二级，二级分类下包含三级
     *
     * @return
     */
    @GetMapping("/category/getBaseCategoryList")
    @Operation(summary = "查询所有分类（1、2、3级分类）")
    public Result<List<JSONObject>> getBaseCategoryList() {
        List<JSONObject> list = baseCategoryService.getBaseCategoryList();
        return Result.ok(list);
    }

    /**
     * 根据三级分类ID(视图主键)查询分类视图对象
     *
     * @param category3Id
     * @return
     */
    @Operation(summary = "根据三级分类ID查询分类视图对象")
    @GetMapping("/category/getCategoryView/{category3Id}")
    public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id) {
        BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
        return Result.ok(baseCategoryView);
    }


    /**
     * 首页中展示指定1级分类下前7个三级分类集合
     *
     * @param category1Id:一级分类ID
     * @return
     */
    @Operation(summary = "首页中展示指定1级分类下前7个三级分类集合")
    @GetMapping("/category/findTopBaseCategory3/{category1Id}")
    public Result<List<BaseCategory3>> getTopBaseCategory3(@PathVariable Long category1Id) {
        List<BaseCategory3> list = baseCategoryService.getTopBaseCategory3(category1Id);
        return Result.ok(list);
    }

    /**
     * 查询指定一级分类下包含二级分类列表（二级分类下三级分类列表
     *
     * @param category1Id 1级分类ID
     * @return
     */
    @Operation(summary = "查询指定一级分类下包含二级分类列表（二级分类下三级分类列表）")
    @GetMapping("/category/getBaseCategoryList/{category1Id}")
    public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id) {
        JSONObject jsonObject1 = baseCategoryService.getBaseCategoryListByCategory1Id(category1Id);
        return Result.ok(jsonObject1);
    }

    /**
     * 查询所有一级分类列表
     *
     * @return
     */
    @Operation(summary = "查询所有一级分类列表")
    @GetMapping("/category/findAllCategory1")
    @GuiGuCache(prefix = "allCategory1")
    public Result<List<BaseCategory1>> getAllCategory() {
        List<BaseCategory1> list = baseCategoryService.list();
        return Result.ok(list);
    }
}

